cmake_minimum_required(VERSION 2.8)

# protobuf
FIND_PACKAGE(Protobuf REQUIRED)
SET(PROTO_META_BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
LIST(APPEND PROTO_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR})
FILE(GLOB PROTOS_FILES "*.proto")
FOREACH(FIL ${PROTOS_FILES})
 GET_FILENAME_COMPONENT(ABS_FIL ${FIL} ABSOLUTE)
 GET_FILENAME_COMPONENT(FIL_NAME ${FIL} NAME)
 string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${FIL_NAME})
 set(FIL_WE ${CMAKE_MATCH_1})
 message(${FIL_WE})
 LIST(APPEND PROTOS_SRCS "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
 LIST(APPEND PROTOS_HDRS "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
 EXECUTE_PROCESS(
     COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ${PROTO_FLAGS} --cpp_out=${PROTO_META_BASE_DIR} ${FIL}
     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 )
ENDFOREACH()

# SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
ADD_LIBRARY(clientServerInterface ${PROTOS_SRCS})
target_link_libraries(clientServerInterface ${PROTOBUF_LIBRARY})
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/lib)